class TreeNode:
    def __init__(self, value=0, left=None, right=None):
        self.value = value
        self.left = left
        self.right = right

# 查找一个树里是否有val元素
def search(root, val):
    # 辅助函数，采用前序遍历的方法，将树的元素一一放到一个列表中
    # 最后我们只需要查找val是否在val中了
    def TreetoList(root, value_list, value):
        if root is None:
            return
        value_list.append(root.value)
        TreetoList(root.left, value_list, value)
        TreetoList(root.right, value_list, value)
    count = []
    TreetoList(root, count, val)
    return val in count

root = TreeNode(4)
root.left = TreeNode(2)
root.right = TreeNode(7)
root.left.left = TreeNode(1)
root.left.right = TreeNode(3)

print(search(root, 2))
print(search(root, 5))
